import { createSlice } from '@reduxjs/toolkit'

export const WriteSlice = createSlice({
    // 命名空间，在调用action的时候会默认的设置为action的前缀,保证唯一.不重名
    name: 'write',
    initialState: {
        tabItems:[
            { key: '0', title: '支出' },
            { key: '1', title: '收入' },
        ],
        WriteItems:{
            billType:'1',
            money:'',
            time: '选择时间',
            type: ['选择','类型'],
            remark:'',
            name:'',
            id:'666',
            billId: "",
        },
        AlterItem:{
        },
        WriteConfirm:[

        ]
    },
    reducers: {
        // 定义的action-赋值的方式进行数据的改变

        AlterItemChange: (state, action) => {
            state.AlterItem =action.payload 
        },
        
    },
})

// 导出action
export const { AlterItemChange } = WriteSlice.actions
export const AlterItemChangeAsync = (amount) => (dispatch) => {
    setTimeout(() => {
        dispatch(AlterItemChange(amount))
    }, 0)
}

// 导出reducer
const WriteSliceReducer = WriteSlice.reducer
export default WriteSliceReducer